home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / TransSkel.cpt / DialogSkel.pas < prev    next >
Pascal/Delphi Source File  |  1987-01-07  |  7KB  |  335 lines

  1. { this program requires MacPasLib, MacTraps, and TransSkelPas in the same    }
  2. { project.  Puts up 2 dialog boxes, whose items affect the other dialog            }
  3. { ported to LS Pascal by Owen Hartnett, Ωhm Software Co.                        }
  4. { 7 January 1987    }
  5.  
  6. PROGRAM DialogSkel;
  7.  
  8.     USES
  9.         TransSkelPas;
  10.  
  11.     CONST
  12.         mDlogRes = 1000;
  13.         aboutAlrtRes = 1001;    { About... alert resource number }
  14.  
  15.         showDlog1 = 1;            { File Menu item numbers            }
  16.         showDlog2 = 2;
  17.         quit = 4;
  18.  
  19.         undo = 1;                     { Edit menu item numbers }
  20.         cut = 3;
  21.         copy = 4;
  22.         paste = 5;
  23.         clear = 6;
  24.  
  25.         button1 = 1;                { dialog item numbers }
  26.         edit1 = 2;
  27.         static1 = 3;
  28.         radio1 = 4;
  29.         radio2 = 5;
  30.         radio3 = 6;
  31.         check1 = 7;
  32.         check2 = 8;
  33.         user1 = 9;
  34.  
  35.     TYPE
  36.         EventPtr = ^EventRecord;
  37.  
  38.     VAR
  39.         mDlog1, mDlog2 : DialogPtr;
  40.  
  41.         iconNum1, iconNum2 : integer;
  42.  
  43.     PROCEDURE DrawIcon (dlog : DialogPtr;
  44.                                     item : integer);
  45.         VAR
  46.             h, itemHandle : Handle;
  47.             itemType : integer;
  48.             itemRect : Rect;
  49.     BEGIN
  50.         GetDItem(dlog, item, itemType, itemHandle, itemRect);
  51.         IF dlog = mDlog1 THEN
  52.             h := GetIcon(iconNum1)
  53.         ELSE
  54.             h := GetICon(iconNum2);
  55.         PlotIcon(itemRect, h);
  56.     END;
  57.  
  58.     FUNCTION GetDctl (dlog : DialogPtr;
  59.                                     item : integer) : Boolean;
  60.  
  61.         VAR
  62.             itemHandle : Handle;
  63.             itemType : integer;
  64.             itemRect : Rect;
  65.  
  66.     BEGIN
  67.         GetDItem(dlog, item, itemType, itemHandle, itemRect);
  68.         GetDCtl := Boolean(GetCtlValue(ControlHandle(itemhandle)));
  69.     END;
  70.  
  71.     PROCEDURE SetDCtl (dlog : DialogPtr;
  72.                                     item : integer;
  73.                                     value : Boolean);
  74.  
  75.         VAR
  76.             itemHandle : Handle;
  77.             itemType : integer;
  78.             itemRect : Rect;
  79.     BEGIN
  80.         GetDItem(dlog, item, itemType, itemHandle, itemRect);
  81.         SetCtlValue(ControlHandle(itemHandle), integer(value));
  82.     END;
  83.  
  84.     PROCEDURE GetDtext (dlog : DialogPtr;
  85.                                     item : integer;
  86.                                     VAR str : Str255);
  87.  
  88.         VAR
  89.             itemHandle : Handle;
  90.             itemType : integer;
  91.             itemRect : Rect;
  92.  
  93.     BEGIN
  94.         GetDItem(dlog, item, itemType, itemHandle, itemRect);
  95.         GetIText(itemHandle, str);
  96.     END;
  97.  
  98.     PROCEDURE SetDText (dlog : DialogPtr;
  99.                                     item : integer;
  100.                                     str : Str255);
  101.         VAR
  102.             itemHandle : Handle;
  103.             itemType : integer;
  104.             itemRect : Rect;
  105.     BEGIN
  106.         GetDItem(dlog, item, itemType, itemHandle, itemRect);
  107.         SetIText(itemHandle, str);
  108.     END;
  109.  
  110.     PROCEDURE SetDProc (dlog : DialogPtr;
  111.                                     item : integer;
  112.                                     p : ProcPtr);
  113.         VAR
  114.             itemHandle : Handle;
  115.             itemType : integer;
  116.             itemRect : Rect;
  117.     BEGIN
  118.         GetDItem(dlog, item, itemType, itemHandle, itemRect);
  119.         SetDITem(dlog, item, itemType, Handle(p), itemRect);
  120.     END;
  121.  
  122.     PROCEDURE SetDRadio (dlog : DialogPtr;
  123.                                     item : integer);
  124.  
  125.         VAR
  126.             partner : DialogPtr;
  127.             itemHandle : Handle;
  128.             itemType : integer;
  129.             itemRect : Rect;
  130.     BEGIN
  131.         partner := DialogPtr(GetWRefCon(dlog));
  132.         SetDCtl(dlog, radio1, item = radio1);
  133.         SetDCtl(dlog, radio2, item = radio2);
  134.         SetDCtl(dlog, radio3, item = radio3);
  135.         IF partner = mDlog1 THEN
  136.             iconNum1 := item - radio1
  137.         ELSE
  138.             iconNum2 := item - radio1;
  139.  
  140.         GetDItem(partner, user1, itemType, itemHandle, itemRect);
  141.         SetPort(partner);
  142.         InvalRect(itemRect);
  143.     END;
  144.  
  145.     PROCEDURE Event (item : integer;
  146.                                     event : EventPtr);
  147.  
  148.         VAR
  149.             actor, partner : DialogPtr;
  150.             title : Str255;
  151.             value : Boolean;
  152.             mypeek : WindowPeek;
  153.             mychar : Boolean;
  154.  
  155.     BEGIN
  156.         GetPort(actor);
  157.         partner := DialogPtr(GetWRefCon(actor));
  158.         CASE item OF
  159.             button1 : 
  160.                 BEGIN
  161.                     GetDText(actor, edit1, title);
  162.                     SetWTitle(partner, title);
  163.                 END;
  164.             radio1 : 
  165.                 SetDRadio(actor, radio1);
  166.             radio2 : 
  167.                 SetDRadio(actor, radio2);
  168.             radio3 : 
  169.                 SetDRadio(actor, radio3);
  170.             check1 : 
  171.                 BEGIN
  172.                     value := NOT (GetDCtl(actor, item));
  173.                     SetDCtl(actor, item, value);
  174.                     IF value = false THEN
  175.                         HideWindow(partner)
  176.                     ELSE
  177.                         ShowWindow(partner);
  178.                 END;
  179.             check2 : 
  180.                 BEGIN
  181.                     value := NOT (GetDCtl(actor, check2));
  182.                     SetDCtl(actor, check2, value);
  183.                     mypeek := WindowPeek(partner);
  184.                     IF value THEN
  185.                         mychar := true
  186.                     ELSE
  187.                         mychar := false;
  188.  
  189.                     mypeek^.goAwayFlag := mychar;
  190.                 END;
  191.             OTHERWISE
  192.         END;
  193.     END;
  194.  
  195.     PROCEDURE Close;
  196.  
  197.         VAR
  198.             actor, partner : DialogPtr;
  199.  
  200.     BEGIN
  201.         GetPort(actor);
  202.         partner := DialogPtr(GetWRefCon(actor));
  203.         HideWindow(actor);
  204.         SetDCtl(partner, check1, false);
  205.     END;
  206.  
  207.     PROCEDURE Clobber;
  208.  
  209.         VAR
  210.             theDialog : DialogPtr;
  211.  
  212.     BEGIN
  213.         GetPort(theDialog);
  214.         DisposDialog(theDialog);
  215.     END;
  216.  
  217. {    File menu handler}
  218.  
  219.     PROCEDURE DoFileMenu (item : integer);
  220.  
  221.     BEGIN
  222.         CASE item OF
  223.             showDlog1 : 
  224.                 BEGIN
  225.                     SelectWindow(mDlog1);
  226.                     ShowWindow(mDlog1);
  227.                     SetDCtl(mDlog2, check1, true);
  228.                 END;
  229.             showDlog2 : 
  230.                 BEGIN
  231.                     SelectWindow(mDlog2);
  232.                     ShowWindow(mDlog2);
  233.                     SetDCtl(mDlog1, check1, true);
  234.                 END;
  235.             quit : 
  236.                 SkelWhoa;
  237.         END;
  238.     END;
  239.  
  240. {    Handle Edit menu items for text window}
  241.  
  242.     PROCEDURE DoEditMenu (item : integer);
  243.  
  244.         VAR
  245.             theDialog : DialogPtr;
  246.             mypeek : WindowPeek;
  247.             ignore : integer;
  248.  
  249.     BEGIN
  250.         theDialog := DialogPtr(FrontWindow);
  251.         mypeek := WindowPeek(theDialog);
  252.         IF mypeek^.windowKind = dialogKind THEN
  253.             CASE item OF
  254.                 cut : 
  255.                     BEGIN
  256.                         DlgCut(theDialog);
  257.                         ignore := ZeroScrap;
  258.                         ignore := TEToScrap;
  259.                     END;
  260.                 copy : 
  261.                     BEGIN
  262.                         DlgCopy(theDialog);
  263.                         ignore := ZeroScrap;
  264.                         ignore := TEToScrap;
  265.                     END;
  266.                 paste : 
  267.                     BEGIN
  268.                         ignore := TEFromScrap;
  269.                         DlgPaste(theDialog);
  270.                     END;
  271.                 clear : 
  272.                     DlgDelete(theDialog);
  273.             END;
  274.     END;
  275.  
  276. {    Handle selection of About… item from Apple menu}
  277.  
  278.     PROCEDURE DoAbout;
  279.  
  280.         VAR
  281.             ignore : integer;
  282.     BEGIN
  283.         ignore := Alert(aboutAlrtRes, NIL);
  284.     END;
  285.  
  286.     FUNCTION DemoDialog (title : Str255;
  287.                                     x, y : integer) : DialogPtr;
  288.  
  289.         VAR
  290.             theDialog : DialogPtr;
  291.  
  292.     BEGIN
  293.         theDialog := GetNewDialog(mDlogRes, NIL, WindowPtr(-1));
  294.         MoveWindow(theDialog, x, y, false);
  295.         SetWTitle(theDialog, title);
  296.         SkelDialog(theDialog, @Event, @Close, @Clobber);
  297.         DemoDialog := theDialog;
  298.     END;
  299.  
  300.     VAR
  301.         m : MenuHandle;
  302.  
  303. BEGIN
  304.     iconNum1 := 0;
  305.     iconNum2 := 0;
  306.     SkelInit;
  307.     SkelApple('AboutDialogSkel...', @DoAbout);
  308.     m := NewMenu(1000, 'File');
  309.     AppendMenu(m, 'Show Dialog 1;Show Dialog 2;(-;Quit/Q');
  310.     SkelMenu(m, @DoFileMenu, NIL);
  311.  
  312.     m := NewMenu(1001, 'Edit');
  313.     AppendMenu(m, '(Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear');
  314.     SkelMenu(m, @DoEditMenu, NIL);
  315.  
  316.     mDlog1 := DemoDialog('Modeless Dialog 1', 50, 50);
  317.     mDlog2 := DemoDialog('Modeless Dialog 2', 150, 200);
  318.     SetWRefCon(WindowPtr(mDlog1), longint(mDlog2));
  319.     SetWRefCon(WindowPtr(mDlog2), longint(mDlog1));
  320.     SetDText(mDlog1, edit1, 'Modeless Dialog 2');
  321.     SetDText(mDlog2, edit1, 'Modeless Dialog 1');
  322.     SetDProc(mDlog1, user1, @DrawIcon);
  323.     SetDProc(mDlog2, user1, @DrawIcon);
  324.     SetDCtl(mDlog1, radio1, true);
  325.     SetDCtl(mDlog2, radio1, true);
  326.     SetDCtl(mDlog1, check1, true);
  327.     SetDCtl(mDlog2, check1, true);
  328.     SetDCtl(mDlog1, check2, true);
  329.     SetDCtl(mDlog2, check2, true);
  330.     ShowWindow(mDlog1);
  331.     ShowWindow(mDlog2);
  332.  
  333.     SkelMain;
  334.     SkelClobber;
  335. END.